home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / mint104s.zoo / mint.src / biosfs.c < prev    next >
C/C++ Source or Header  |  1993-03-08  |  34KB  |  1,486 lines

  1. /*
  2. Copyright 1991,1992 Eric R. Smith. All rights reserved.
  3.  */
  4.  
  5. /* simple biosfs.c */
  6.  
  7. #include "mint.h"
  8.  
  9. extern struct kerinfo kernelinfo;    /* see main.c */
  10.  
  11. static long    ARGS_ON_STACK bios_root    P_((int drv, fcookie *fc));
  12. static long    ARGS_ON_STACK bios_lookup    P_((fcookie *dir, const char *name, fcookie *fc));
  13. static long    ARGS_ON_STACK bios_getxattr    P_((fcookie *fc, XATTR *xattr));
  14. static long    ARGS_ON_STACK bios_chattr    P_((fcookie *fc, int attrib));
  15. static long    ARGS_ON_STACK bios_chown    P_((fcookie *fc, int uid, int gid));
  16. static long    ARGS_ON_STACK bios_chmode    P_((fcookie *fc, unsigned mode));
  17. static long    ARGS_ON_STACK bios_rmdir    P_((fcookie *dir, const char *name));
  18. static long    ARGS_ON_STACK bios_remove    P_((fcookie *dir, const char *name));
  19. static long    ARGS_ON_STACK bios_getname    P_((fcookie *root, fcookie *dir, char *pathname, int size));
  20. static long    ARGS_ON_STACK bios_rename    P_((fcookie *olddir, char *oldname,
  21.                     fcookie *newdir, const char *newname));
  22. static long    ARGS_ON_STACK bios_opendir    P_((DIR *dirh, int flags));
  23. static long    ARGS_ON_STACK bios_readdir    P_((DIR *dirh, char *nm, int nmlen, fcookie *fc));
  24. static long    ARGS_ON_STACK bios_rewinddir    P_((DIR *dirh));
  25. static long    ARGS_ON_STACK bios_closedir    P_((DIR *dirh));
  26. static long    ARGS_ON_STACK bios_pathconf    P_((fcookie *dir, int which));
  27. static long    ARGS_ON_STACK bios_dfree    P_((fcookie *dir, long *buf));
  28. static DEVDRV *    ARGS_ON_STACK bios_getdev    P_((fcookie *fc, long *devspecial));
  29. static long    ARGS_ON_STACK bios_fscntl    P_((fcookie *, const char *, int, long));
  30. static long    ARGS_ON_STACK bios_symlink    P_((fcookie *, const char *, const char *));
  31. static long    ARGS_ON_STACK bios_readlink    P_((fcookie *, char *, int));
  32.  
  33. static long    ARGS_ON_STACK bios_topen    P_((FILEPTR *f));
  34. static long    ARGS_ON_STACK bios_twrite    P_((FILEPTR *f, const char *buf, long bytes));
  35. static long    ARGS_ON_STACK bios_tread    P_((FILEPTR *f, char *buf, long bytes));
  36. static long    ARGS_ON_STACK bios_nwrite    P_((FILEPTR *f, const char *buf, long bytes));
  37. static long    ARGS_ON_STACK bios_nread    P_((FILEPTR *f, char *buf, long bytes));
  38. static long    ARGS_ON_STACK bios_ioctl    P_((FILEPTR *f, int mode, void *buf));
  39. static long    ARGS_ON_STACK bios_select    P_((FILEPTR *f, long p, int mode));
  40. static void    ARGS_ON_STACK bios_unselect    P_((FILEPTR *f, long p, int mode));
  41. static long    ARGS_ON_STACK bios_tseek    P_((FILEPTR *f, long where, int whence));
  42.  
  43. long    ARGS_ON_STACK null_open    P_((FILEPTR *f));
  44. long    ARGS_ON_STACK null_write    P_((FILEPTR *f, const char *buf, long bytes));
  45. long    ARGS_ON_STACK null_read    P_((FILEPTR *f, char *buf, long bytes));
  46. long    ARGS_ON_STACK null_lseek    P_((FILEPTR *f, long where, int whence));
  47. long    ARGS_ON_STACK null_ioctl    P_((FILEPTR *f, int mode, void *buf));
  48. long    ARGS_ON_STACK null_datime    P_((FILEPTR *f, short *time, int rwflag));
  49. long    ARGS_ON_STACK null_close    P_((FILEPTR *f, int pid));
  50. long    ARGS_ON_STACK null_select    P_((FILEPTR *f, long p, int mode));
  51. void    ARGS_ON_STACK null_unselect    P_((FILEPTR *f, long p, int mode));
  52.  
  53. static long ARGS_ON_STACK mouse_open    P_((FILEPTR *f));
  54. static long ARGS_ON_STACK mouse_read    P_((FILEPTR *f, char *buf, long nbytes));
  55. static long ARGS_ON_STACK mouse_ioctl P_((FILEPTR *f, int mode, void *buf));
  56. static long ARGS_ON_STACK mouse_close P_((FILEPTR *f, int pid));
  57. static long ARGS_ON_STACK mouse_select P_((FILEPTR *f, long p, int mode));
  58. static void ARGS_ON_STACK mouse_unselect P_((FILEPTR *f, long p, int mode));
  59.  
  60. /* device driver for BIOS terminals */
  61.  
  62. DEVDRV bios_tdevice = {
  63.     bios_topen, bios_twrite, bios_tread, bios_tseek, bios_ioctl,
  64.     null_datime, null_close, bios_select, bios_unselect
  65. };
  66.  
  67. /* device driver for BIOS devices that are not terminals */
  68.  
  69. DEVDRV bios_ndevice = {
  70.     null_open, bios_nwrite, bios_nread, null_lseek, bios_ioctl,
  71.     null_datime, null_close, bios_select, bios_unselect
  72. };
  73.  
  74. DEVDRV null_device = {
  75.     null_open, null_write, null_read, null_lseek, null_ioctl,
  76.     null_datime, null_close, null_select, null_unselect
  77. };
  78.  
  79. DEVDRV mouse_device = {
  80.     mouse_open, null_write, mouse_read, null_lseek, mouse_ioctl,
  81.     null_datime, mouse_close, mouse_select, mouse_unselect
  82. };
  83.  
  84. /* this special driver is checked for in dosfile.c, and indicates that
  85.  * a dup operation is actually wanted rather than an open
  86.  */
  87. DEVDRV fakedev;
  88.  
  89. #ifdef FASTTEXT
  90. extern DEVDRV screen_device;    /* see fasttext.c */
  91. #endif
  92.  
  93. FILESYS bios_filesys = {
  94.     (FILESYS *)0,
  95.     FS_LONGPATH,
  96.     bios_root,
  97.     bios_lookup, nocreat, bios_getdev, bios_getxattr,
  98.     bios_chattr, bios_chown, bios_chmode,
  99.     nomkdir, bios_rmdir, bios_remove, bios_getname, bios_rename,
  100.     bios_opendir, bios_readdir, bios_rewinddir, bios_closedir,
  101.     bios_pathconf, bios_dfree, nowritelabel, noreadlabel,
  102.     bios_symlink, bios_readlink, nohardlink, bios_fscntl, nodskchng
  103. };
  104.  
  105.  
  106. struct tty con_tty, aux_tty, midi_tty;
  107. struct tty sccb_tty, scca_tty, ttmfp_tty;
  108.  
  109. #define BNAME_MAX    13
  110.  
  111. struct bios_file {
  112.     char     name[BNAME_MAX+1];    /* device name */
  113.     DEVDRV *device;            /* device driver for device */
  114.     short    private;        /* extra info for device driver */
  115.     ushort    flags;            /* flags for device open */
  116.     struct tty *tty;        /* tty structure (if appropriate) */
  117.     struct bios_file *next;
  118. };
  119.  
  120. struct bios_file BDEV[] = {
  121.  
  122. /* "real" bios devices present on all machines */
  123.     {"centr", &bios_ndevice, 0, 0, 0, 0},
  124.     {"console", &bios_tdevice, 2, O_TTY, &con_tty, 0},
  125.     {"midi", &bios_tdevice, 3, O_TTY, &midi_tty, 0},
  126.     {"kbd", &bios_ndevice, 4, 0, 0, 0},
  127. /* devices that duplicate handles */
  128.     {"prn", &fakedev, -3, 0, 0, 0}, /* handle -3 (printer) */
  129.     {"aux", &fakedev, -2, 0, 0, 0}, /* handle -2 (aux. terminal) */
  130.     {"con", &fakedev, -1, 0, 0, 0}, /* handle -1 (control terminal) */
  131.     {"tty", &fakedev, -1, 0, 0, 0}, /* the Unix name for it */
  132.     {"stdin", &fakedev, 0, 0, 0, 0},  /* handle 0 (stdin) */
  133.     {"stdout", &fakedev, 1, 0, 0, 0}, /* handle 1 (stdout) */
  134.     {"stderr", &fakedev, 2, 0, 0, 0}, /* handle 2 (stderr) */
  135.  
  136. /* other miscellaneous devices */
  137.     {"mouse", &mouse_device, 0, 0, 0, 0},
  138.     {"null", &null_device, 0, 0, 0, 0},
  139.  
  140. #ifdef FASTTEXT
  141. /* alternate console driver */
  142.     {"fasttext", &screen_device, 2, O_TTY, &con_tty, 0},
  143. #endif
  144.  
  145. /* serial port things *must* come last, because not all of these
  146.  * are present on all machines (except for modem1, which does however
  147.  * have a different device number on TTs and STs)
  148.  */
  149.     {"modem1", &bios_tdevice, 6, O_TTY, &aux_tty, 0},
  150.     {"modem2", &bios_tdevice, 7, O_TTY, &sccb_tty, 0},
  151.     {"serial1", &bios_tdevice, 8, O_TTY, &ttmfp_tty, 0},
  152.     {"serial2", &bios_tdevice, 9, O_TTY, &scca_tty, 0},
  153.     {"", 0, 0, 0, 0, 0}
  154. };
  155.  
  156. struct bios_file *broot, *bdevlast;
  157.  
  158. /* a file pointer for BIOS device 1, provided only for insurance
  159.  * in case a Bconmap happens and we can't allocate a new FILEPTR;
  160.  * in most cases, we'll want to build a FILEPTR in the usual
  161.  * way.
  162.  */
  163.  
  164. FILEPTR *defaultaux;
  165.  
  166. void
  167. biosfs_init()
  168. {
  169.     struct bios_file *b;
  170.  
  171.     broot = BDEV;
  172.  
  173.     for (b = broot; b->name[0]; b++) {
  174.         b->next = b+1;
  175.  
  176.     /* if not a TT or Mega STE, adjust the MODEM1 device to be BIOS
  177.      * device 1
  178.      * and ignore the remaining devices, since they're not present
  179.      */
  180.         if (!has_bconmap && b->private == 6) {
  181.             b->private = 1;
  182.             b->next = 0;
  183.             break;
  184.         }
  185.     /* SERIAL2 is not present on the Mega STe */
  186.         if (mch == MEGASTE && b->private == 8) {
  187.             b->next = 0;
  188.             break;
  189.         }
  190.             
  191.     }
  192.     bdevlast = b;
  193.     if (b->name[0] == 0) {
  194.         --b;
  195.         b->next = 0;
  196.     }
  197.     defaultaux = new_fileptr();
  198.     defaultaux->links = 1;        /* so it never gets freed */
  199.     defaultaux->flags = O_RDWR;
  200.     defaultaux->pos = 0;
  201.     defaultaux->devinfo = 0;
  202.     defaultaux->fc.fs = &bios_filesys;
  203.     defaultaux->fc.index = 0;
  204.     defaultaux->fc.aux = 1;
  205.     defaultaux->fc.dev = BIOSDRV;
  206.     defaultaux->dev = &bios_ndevice;
  207. }
  208.  
  209. static long ARGS_ON_STACK 
  210. bios_root(drv, fc)
  211.     int drv;
  212.     fcookie *fc;
  213. {
  214.     if (drv == BIOSDRV) {
  215.         fc->fs = &bios_filesys;
  216.         fc->dev = drv;
  217.         fc->index = 0L;
  218.         return 0;
  219.     }
  220.     fc->fs = 0;
  221.     return EINTRN;
  222. }
  223.  
  224. static long ARGS_ON_STACK 
  225. bios_lookup(dir, name, fc)
  226.     fcookie *dir;
  227.     const char *name;
  228.     fcookie *fc;
  229. {
  230.     struct bios_file *b;
  231.  
  232.     if (dir->index != 0) {
  233.         DEB